package com.zsh.fmmall.service.impl;

import com.zsh.fmmall.dao.CategoryMapper;
import com.zsh.fmmall.entity.CategoryVO;
import com.zsh.fmmall.service.CategoryService;
import com.zsh.fmmall.vo.BaseCode;
import com.zsh.fmmall.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.security.Principal;
import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;

//    商品分类列表的连接查询操作
    @Override
    public ResultVO listCategories() {
        List<CategoryVO> categoryVOS = categoryMapper.selectAllCategories();
        if(categoryVOS.size()==0){
            return new ResultVO(BaseCode.no,"false",null);
        }
        return new ResultVO(BaseCode.ok,"success",categoryVOS);
    }

//    商品分类列表的子查询操作。
    public ResultVO listCategories2() {
        List<CategoryVO> categoryVOS = categoryMapper.selectAllCategories2(0);
        if(categoryVOS.size()==0){
            return new ResultVO(BaseCode.no,"false",null);
        }
        return new ResultVO(BaseCode.ok,"success",categoryVOS);
    }
//首页-分类商品推荐
    @Override
    public ResultVO listFirstLevelCategories() {
        List<CategoryVO> categoryVOS = categoryMapper.selectFirstLevelCategories();
        if(categoryVOS.size()==0){
            return new ResultVO(BaseCode.no,"false",null);
        }
        return new ResultVO(BaseCode.ok,"success",categoryVOS);
    }
}
